package gek.uni.diplom.integrate.wizard.composites;

import gek.uni.diplom.integrate.wizard.providers.ProjectContentProvider;
import gek.uni.diplom.integrate.wizard.providers.ProjectLabelProvider;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

public class ProjectSelectComposite extends Composite {

  IProject[] projects;
  private TableViewer projectsViewer;

  public ProjectSelectComposite(Composite parent, int style, IProject[] projects) {
    super(parent, style);
    this.projects = projects;
    createContents();
  }

  private void createContents() {
    this.setLayout(new GridLayout(1, true));
    Composite innerComposite = new Composite(this, SWT.NONE);
    innerComposite.setBackground(innerComposite.getShell().getDisplay()
        .getSystemColor(SWT.COLOR_GREEN));
    innerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    innerComposite.setLayout(new GridLayout(1, true));
    projectsViewer = new TableViewer(innerComposite);
    projectsViewer.getControl().setLayoutData(
        new GridData(SWT.FILL, SWT.FILL, true, true));
    projectsViewer.setContentProvider(new ProjectContentProvider());
    projectsViewer.setLabelProvider(new ProjectLabelProvider());
    ISelection selection = new StructuredSelection(projects);
    projectsViewer.setInput(projects);
//    projectsViewer.setSelection(selection);
  }

}
